番外編Agones FleetAutoscaleRequestMetaData & 軽いContribute編
こんにちは、@sugar235711です。
この記事は「ひとりで気になるOSSのソースコード全部読んで何かする Advent Calendar 2025」6日目の記事です。
今回からこのアドベントカレンダーの記事はCosenseに書いていきます。なんとなく気分です。
前日の記事はこちら: FleetAutoscaler編
全体編
GameServer編
Fleet編
GameServerAllocation編
FleetAutoscaler編
Agones FleetAutoscaleRequestMetaData & 軽いContribute編 ←今ここ
今日は番外編です。
せっかく全部ソースコード読んだのでIssueも眺めていたのですが、軽いDocs系くらいしかサクッとできるものがなさそうだったのでとりあえずDocsで記念Contributeしておきました。(OpenCensusからの移行とかおもろそうなのはあったんですが時間をかける必要がありそうなのでチマチマ見て行こうかなと思っています)
https://github.com/googleforgames/agones/pull/4365
FleetAutoscaleRequestMetaDataに関して
この機能は先日リリースされた1.54.0でBetaへ昇格された機能です。ベータになるとフィーチャーゲートはデフォルトで有効になります。
https://github.com/googleforgames/agones/releases/tag/v1.54.0
機能としてはFleetのyamlで設定する labels と annotations が FleetAutoscaleRequest に含まれるようになり、Webhook経由のAutoScaleではは Fleet 固有のメタデータに基づいてスケーリングの判断を行えるようになります。(ちなみに今後実装予定のWasm AutoScaleの方でも使えるようになります)
code:go
type FleetAutoscaleRequest struct {
// UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are
// otherwise identical (parallel requests, requests when earlier requests did not modify etc)
// The UID is meant to track the round trip (request/response) between the Autoscaler and the WebHook, not the user request.
// It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging.
UID types.UID json:"uid""
// Name is the name of the Fleet being scaled
Name string json:"name"
// Namespace is the namespace associated with the request (if any).
Namespace string json:"namespace"
// The Fleet's status values
Status v1.FleetStatus json:"status"
// Standard map labels; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels.
Labels mapstringstring json:"labels,omitempty"
// Standard map annotations; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations.
Annotations mapstringstring json:"annotations,omitempty"
}
Autoscaleの各実装は下記を見てください。
FleetAutoscaler編
Contributeに関して
Docsの更新だけなので大したContributeはしていないですが本体以外の部分に関しても触れておきます。
AgonesのドキュメントはHugoで作成されています。
https://agones.dev/site/docs/contribute/documentation-editing-contribution/
HugoではFeature Gateの機能に関してはshortcodeのブロックでバージョンごとに表示・非表示の制御が行われています。
https://github.com/googleforgames/agones/blob/main/site/layouts/shortcodes/feature.html
htmlのテンプレートが用意されており、現在のリリースバージョンがpublishVersion以上かつexpiryVersion未満の場合のみ、囲まれたコンテンツを表示する、といった制御がされます。
code:html
{{- with or (.Get "publishVersion") (.Get "expiryVersion")}}
{{- else }}
{{ errorf "missing value for either publishVersion or expiryVersion: %s" .Position}}
{{- end}}
{{- $publishVersion := (.Get "publishVersion" ) | default "0.0.0" }}
{{- $expiryVersion := (.Get "expiryVersion") | default "9999.0.0"}}
{{- $publDigits := split $publishVersion "." }}
{{- $curDigits := split $version "." }}
{{- $expDigits := split $expiryVersion "." }}
今回対応したのはこの辺です。
https://github.com/googleforgames/agones/commit/e9f4ba83226a3cedc2fe8bbc4945245367cd2c8a
shortcodeがビルド時にバージョンを比較して、条件に合うコンテンツのみをHTMLに含めるような挙動になります。
code:mk
feature-shortcode-update: ensure-build-image
docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \
go run build/scripts/feature-shortcode-update/main.go -version=$(version)
https://github.com/googleforgames/agones/blob/main/build/includes/website.mk
なのでContributeする側はテンプレートに合わせてpublishVersionとexpiryVersionを追加箇所に記入してるあげで対応が完了します。非常に楽ですね。
CI/CDに関して
Google関連のOSSにContributeする際はCLAに署名する必要があります。(昔対応していたので割愛)
https://cla.developers.google.com/clas
レビュー過程ではGoole Cloud Buildを使った実際のクラウド環境内でのビルドが行われます。(今回はdocsの更新なのであんまり関係はない)
レビュアーが/gcbrunと書き込むことで手動でトリガーするようにしているぽいです。
https://github.com/googleforgames/agones/blob/main/cloudbuild.yaml
ちなみにこのビルドの中では下記のような検証が行われています。
コード生成の検証(CRD)
Lint
ビルド
SDK ビルド
ユニットテスト
ウェブサイトプレビュー生成
E2Eテスト(GKE)
Kubernetes 1.32 (generic) - us-west1
Kubernetes 1.33 (generic) - asia-east1
Kubernetes 1.34 (generic) - europe-west1
Kubernetes 1.32 (GKE Autopilot) - us-west1
Kubernetes 1.33 (GKE Autopilot) - asia-east1
Kubernetes 1.34 (GKE Autopilot) - europe-west1
モック等ではなく実際のGKEを利用したE2Eテストも行われています。
リソース
https://github.com/googleforgames/agones/blob/main/build/terraform/e2e/module.tf
テスト内容
https://github.com/googleforgames/agones/blob/main/test/e2e/gameserver_test.go
これによって各バージョンで実際の環境で動作検証を行い、ユーザーが安全にCustom Resourceを使えるような環境になっているんだなあと思いました。
まとめ
ここまでAgonesを見ていきました、せっかくコードを全部読んだので継続的にコントリビュートできるように注視していこうと思います。